<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		
	<span class="different-posts different-posts_earlier">📖 <a href="/page/24">earlier posts</a> 📖</span>




	<article>
	
		<h1><a href="/2017/10/12/Nginx/21. nginx 访问控制/">nginx 访问控制</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/LNMP/">LNMP</a> <a class="article__tag-link" href="/tags/Nginx/">Nginx</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;限制只让某个 ip 访问：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">allow 127.0.0.1;</div><div class="line">deny all;</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/nginx%20%E8%AE%BF%E9%97%AE%E6%8E%A7%E5%88%B6/01.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;只允许127.0.0.1 访问 admin.php </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;禁止某个 ip 或者 ip 段访问站点的设置方法，首先建立建立配置文件放在 nginx 的 conf 目录下面，命名为 deny.ip</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">cat deny.ip</div><div class="line">deny 192.168.1.11;</div><div class="line">deny 192.168.1.123;</div><div class="line">deny 10.0.1.0/24;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在对应的虚拟主机配置文件中加入：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">inclued deny.ip</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;重启一下 nginx 服务：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@lnmp ~]<span class="comment"># service nginx reload</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;deny.ip 的格式中也可以用 deny all；</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;要实现这样的应用，除了几个 ip 外，其他全部拒绝，需要编辑 deny.ip ：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">cat deny.ip</div><div class="line">allow 1.1.1.1;</div><div class="line">allow 1.1.1.2;</div><div class="line">deny all;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;当然也可以每台虚拟主机配置文件里去更改。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;有时候会根据目录来显示 php 解析</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">location ~ .*(diy|template|attachments|forumdata|attachment|image)/.*\.php$</div><div class="line">&#123;</div><div class="line">    deny all;</div><div class="line">&#125;</div><div class="line">`</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/nginx%20%E8%AE%BF%E9%97%AE%E6%8E%A7%E5%88%B6/02.png?raw=true" alt=""></figure></p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Nginx/20. nginx配置防盗链/">nginx配置防盗链</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/LNMP/">LNMP</a> <a class="article__tag-link" href="/tags/Nginx/">Nginx</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;防盗链也可以和配置静态文件过期时间一样，和指定文件类型不记录配置在一起。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|rar|zip|doc|pdf|gz|bz2|xls)$</div><div class="line">&#123; </div><div class="line">expires 30d;</div><div class="line">access_log off;</div><div class="line">valid_referers none blocked server_name *.123.com *.234.com *.baidu.com;</div><div class="line"><span class="keyword">if</span> (<span class="variable">$invalid_referer</span>)</div><div class="line">&#123;</div><div class="line"><span class="comment">#deny all;</span></div><div class="line"><span class="built_in">return</span> 403;</div><div class="line">rewrite ^/ http://www.example.com/nophoto.gif;</div><div class="line">&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;valid_referers none blocked server_name 表示对这些域名的网站不进行盗链。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后 if ，可以 deny all 也可以 return 403，然后 rewrite 到一个403的固定网页。这样盗链文件的人访问这些文件时就会跳到 <a href="http://www.example.com/nophoto.gif" target="_blank" rel="external">http://www.example.com/nophoto.gif</a> 这里。当然也可以直接显示 403，即 return 403; 着两种方式 return 403 更节省资源。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">location ~ *^.+\.(gif|jpg|jpeg|png|bmp|swf|flv|rar|zip|doc|pdf|gz|bz2|xls)$</div><div class="line">&#123; </div><div class="line">expires 30d;</div><div class="line">valid_referers none blocked server_name *.123.com *.234.com *.baidu.com;</div><div class="line"><span class="keyword">if</span> (<span class="variable">$invalid_referer</span>)</div><div class="line">&#123;</div><div class="line"><span class="comment">#deny all;</span></div><div class="line"><span class="built_in">return</span> 403;</div><div class="line">rewrite ^/ http://www.example.com/nophoto.gif;</div><div class="line">&#125;</div><div class="line">access_log off;</div><div class="line">&#125;</div></pre></td></tr></table></figure>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Nginx/19. nginx 配置静态文件过期时间/">nginx 配置静态文件过期时间</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/LNMP/">LNMP</a> <a class="article__tag-link" href="/tags/Nginx/">Nginx</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;可以把指定文件类型不记录日志和该功能一起配置。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$</div><div class="line">&#123;</div><div class="line">    expires 30d;</div><div class="line">    access_log off;</div><div class="line">&#125;</div><div class="line"></div><div class="line">location ~ .*\.(js|css)$</div><div class="line">&#123;</div><div class="line">    expires 12h;</div><div class="line">    access_log off;</div><div class="line">&#125;</div></pre></td></tr></table></figure>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Nginx/2. Nginx测试php解析/">Nginx测试php解析</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/LNMP/">LNMP</a> <a class="article__tag-link" href="/tags/Nginx/">Nginx</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建测试文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">vim /usr/<span class="built_in">local</span>/nginx/html/2.php</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加内容：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">&lt;?php</div><div class="line"><span class="built_in">echo</span> <span class="string">"测试php是否解析"</span>;</div><div class="line">?&gt;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;测试：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@localhost nginx]<span class="comment"># curl localhost/2.php</span></div><div class="line">测试php是否解析</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;显示成这样，才说明 PHP 解析正常</p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Nginx/17. nginx 不记录指定文件类型的日志/">nginx 不记录指定文件类型的日志</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/LNMP/">LNMP</a> <a class="article__tag-link" href="/tags/Nginx/">Nginx</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;先看看 nginx 日志相关配置</p>
<h2 id="1-日志格式"><a href="#1-日志格式" class="headerlink" title="1.日志格式"></a>1.日志格式</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在 nginx.conf 中定义日志格式</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@lnmp ~]<span class="comment"># vim /usr/local/nginx/conf/nginx.conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;配置如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">log_format combined_realip <span class="string">'$remote_addr $http_x_forwarded_for [$time_local]'</span></div><div class="line"><span class="string">'$host "$request_uri" $status'</span></div><div class="line"><span class="string">'"$http_referer" "$http_user_agent"'</span>;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明：remote_addr 表示远程的 ip ；http_x_forwarded_for 表示代理的 ip ；time_local 表示时间；host 表示域名；request_uri  表示访问的地址；status 表示状态码；http_referer 表示referer ； http_user_agent 表示user_agent用户代理；</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这个格式该怎么去使用，在虚拟主机配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@lnmp ~]<span class="comment"># vim /usr/local/nginx/conf/vhosts/123.conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">access_log /tmp/access.log combined_realip;</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/nginx%20%E4%B8%8D%E8%AE%B0%E5%BD%95%E6%8C%87%E5%AE%9A%E6%96%87%E4%BB%B6%E7%B1%BB%E5%9E%8B%E7%9A%84%E6%97%A5%E5%BF%97/01.png?raw=true" alt=""></figure></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@lnmp ~]<span class="comment"># service nginx configtest</span></div><div class="line">[root@lnmp ~]<span class="comment"># service nginx reload</span></div><div class="line">[root@lnmp ~]<span class="comment"># curl -x127.0.0.1:80 www.123.com/1234 -I</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这样 /tmp 下就会生成 access.log </p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/nginx%20%E4%B8%8D%E8%AE%B0%E5%BD%95%E6%8C%87%E5%AE%9A%E6%96%87%E4%BB%B6%E7%B1%BB%E5%9E%8B%E7%9A%84%E6%97%A5%E5%BF%97/02.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;下面的日志格式，会记录代理的 ip 和 真实客户端真实 ip ，建议使用</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">log_format combined_realip <span class="string">'$proxy_add_x_forwarded_for - $remote_user [$time_local]'</span></div><div class="line"><span class="string">'"$request" $status $body_byres_sent'</span></div><div class="line"><span class="string">'"$http_referer" "$http_user_agent"'</span>;</div></pre></td></tr></table></figure>
<h2 id="2-错误日志-error-log-日志级别"><a href="#2-错误日志-error-log-日志级别" class="headerlink" title="2.错误日志 error_log 日志级别"></a>2.错误日志 error_log 日志级别</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在常见的502中已经提到过这个概念。error_log 级别分为 debug，info，notice，warn，error，crit 默认为 crit ，该级别在日志名后边定义格式如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">error_log /usr/<span class="built_in">local</span>/nginx/logs/nginx_error.log crit;</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/nginx%20%E4%B8%8D%E8%AE%B0%E5%BD%95%E6%8C%87%E5%AE%9A%E6%96%87%E4%BB%B6%E7%B1%BB%E5%9E%8B%E7%9A%84%E6%97%A5%E5%BF%97/03.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;crit 记录的日志最少，而 debug 记录的日志最多。如果 nginx 遇到一些问题，比如 502 比较频繁出现，但是看默认的 error_log 并没有看到有意义的信息，那么就可以调一下错误日志的级别，当调成 error 级别时，错误日志记录的内容会更加丰富。    </p>
<h2 id="3-某些类型的文件不记录日志"><a href="#3-某些类型的文件不记录日志" class="headerlink" title="3.某些类型的文件不记录日志"></a>3.某些类型的文件不记录日志</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改虚拟主机配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@lnmp ~]<span class="comment"># vim /usr/local/nginx/conf/vhosts/123.conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;配置内容：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$</div><div class="line"> &#123;</div><div class="line"> access.log off;</div><div class="line"> &#125;</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/nginx%20%E4%B8%8D%E8%AE%B0%E5%BD%95%E6%8C%87%E5%AE%9A%E6%96%87%E4%BB%B6%E7%B1%BB%E5%9E%8B%E7%9A%84%E6%97%A5%E5%BF%97/04.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这样就不会记录以上类型的日志，其实 static 和cache 的相关日志也可以禁止</p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Nginx/18. nginx日志切割/">nginx日志切割</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/LNMP/">LNMP</a> <a class="article__tag-link" href="/tags/Nginx/">Nginx</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;nginx 没有 apache自动切割的工具，只有写脚本，也可以借助 centos 自带的日志归档工具 logrotate 。</p>
<h2 id="1-nginx-日志切割脚本"><a href="#1-nginx-日志切割脚本" class="headerlink" title="1.nginx 日志切割脚本"></a>1.nginx 日志切割脚本</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先确定访问日志路径，假定为 /tmp/axxess.log ，还要确定 nginx 的 pid 文件所在路径，假定为 /usr/local/nginx/var/nginx.pid。下面开始写日志</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">[root@lnmp ~]<span class="comment"># vim /usr/local/sbin/nginx_logrotate.sh</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="meta">#!/bin/bash</span></div><div class="line">d=`data -d <span class="string">"-1 day"</span> +%F`</div><div class="line">[ -d /tmp/nginx_log ] || mkdir /tmp/nginx_log</div><div class="line">mv /tmp/access.log /tmp/nginx_log/<span class="variable">$d</span>.<span class="built_in">log</span></div><div class="line">/etc/init.d/nginx reload &gt; /dev/null</div><div class="line"><span class="built_in">cd</span> /tmp/nginx_log/</div><div class="line">gizp -f <span class="variable">$d</span>.<span class="built_in">log</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;d=<code>data -d &quot;-1 day&quot; +%F</code> 表示时间，切割前一天的日志；</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;[ -d /tmp/nginx_log ] || mkdir /tmp/nginx_log 判断归档目录存在不存在，存在就进行下一步，不存在就创建； </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mv /tmp/access.log /tmp/nginx_log/$d.log 把日志移动到归档目录，文件名$d根据时创建；</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;/etc/init.d/nginx reload &gt; /dev/null 移动日志以后需要重新创建access.log 重新加载 nginx 就可以，然后把重新加载的输出日志重定向到 /dec/null；</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cd /tmp/nginx_log/ 进入归档目录；</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cd /tmp/nginx_log/ 如果日志比较大，压缩归档文件方便保存，-f 表示强制覆盖。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;最后写一个计划任务，每天0点0分执行脚本。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@lnmp ~]<span class="comment"># crontab -e</span></div><div class="line"></div><div class="line">0 0 * * * /bin/bash /usr/<span class="built_in">local</span>/sbin/nginx_logrotate.sh</div></pre></td></tr></table></figure>
<h2 id="2-借助系统的-logrotate-工具实现"><a href="#2-借助系统的-logrotate-工具实现" class="headerlink" title="2.借助系统的 logrotate 工具实现"></a>2.借助系统的 logrotate 工具实现</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@lnmp ~]<span class="comment"># vim /etc/logrotate.d/nginx</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;加入内容：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">/tmp/*.<span class="built_in">log</span> &#123;</div><div class="line">Daily</div><div class="line">Missingok</div><div class="line">rotate 52</div><div class="line">compress</div><div class="line">delaycompress</div><div class="line">notifempty</div><div class="line">create 644 nobody nobody</div><div class="line">sharedscripts</div><div class="line">postrotate</div><div class="line">[ -f /usr/<span class="built_in">local</span>/nginx/var/nginx.pid ] &amp;&amp; <span class="built_in">kill</span> -USR1 `cat /usr/<span class="built_in">local</span>/nginx/var/nginx.pid`</div><div class="line">Endscript</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明：</p>
<ul>
<li>daily 表示日志按天归档；</li>
<li>missingok 表示忽略所有错误，比如日志文件不存在的情况下；</li>
<li>rotate 52 表示存放的日志个数，最多就52个，最老的会被删除；</li>
<li>compress 表示日志要压缩；</li>
<li>delaycopress 表示压缩除了当前和最近之外的所有其他版本；</li>
<li>notifempty 表示如果日志为空，则不归档；</li>
<li>create 644 nobody nobody 定义归档日志的权限以及属主和属组；</li>
<li>sharedscripts 表示所有的日志共享该脚本，因为这里指定的日志文件为多个，用来*.log；</li>
<li>portrotate 后边跟轮换过日志之后要运行的命令；</li>
<li>endscript 表示结束了。</li>
</ul>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Nginx/16. nginx的301与302如何配置/">nginx的301与302如何配置</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/LNMP/">LNMP</a> <a class="article__tag-link" href="/tags/Nginx/">Nginx</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先看一个完整代码示例，关于nginx 301 302跳转的。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;301跳转设置：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">server &#123;</div><div class="line">listen 80;</div><div class="line">server_name 123.com;</div><div class="line">rewrite ^/(.*) http://456.com/<span class="variable">$1</span> permanent;</div><div class="line">access_log off;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;302跳转设置：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">server &#123;</div><div class="line">listen 80;</div><div class="line">server_name 123.com;</div><div class="line">rewrite ^/(.*) http://456.com/<span class="variable">$1</span> redirect;</div><div class="line">access_log off;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在看下关于nginx 301 302跳转的详细说明文档</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">server &#123;</div><div class="line">server_name test.com;</div><div class="line">rewrite ^/(.*) http://www.test1.com/<span class="variable">$1</span> permanent;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;last – 基本上都用这个Flag。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;break – 中止Rewirte，不在继续匹配</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redirect – 返回临时重定向的HTTP状态302</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;permanent – 返回永久重定向的HTTP状态301</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Nginx的重定向用到了Nginx的HttpRewriteModule，下面简单解释以下如何使用的方法：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;rewrite命令</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;nginx的rewrite相当于apache的rewriterule(大多数情况下可以把原有apache的rewrite规则加上引号就可以直接使用)，它可以用在server,location 和IF条件判断块中,命令格式如下：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;rewrite 正则表达式 替换目标 flag标记</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;flag标记可以用以下几种格式：</p>
<ul>
<li>last – 基本上都用这个Flag。</li>
<li>break – 中止Rewirte，不在继续匹配</li>
<li>redirect – 返回临时重定向的HTTP状态302</li>
<li>permanent – 返回永久重定向的HTTP状态301</li>
</ul>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;特别注意：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;last和break用来实现URL重写，浏览器地址栏的URL地址不变，但是在服务器端访问的路径发生了变化；</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redirect和permanent用来实现URL跳转，浏览器地址栏会显示跳转后的URL地址；</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;例如下面这段设定nginx将某个目录下面的文件重定向到另一个目录,$2对应第二个括号(.*)中对应的字符串：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">location /download/ &#123;</div><div class="line">    rewrite ^(/download/.*)/m/(.*)\..*$ <span class="variable">$1</span>/nginx-rewrite/<span class="variable">$2</span>.gz <span class="built_in">break</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;nginx重定向的IF条件判断</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在server和location两种情况下可以使用nginx的IF条件判断，条件可以为以下几种：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;正则表达式</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如：匹配判断</p>
<ul>
<li>~ 为区分大小写匹配; !~为区分大小写不匹配</li>
<li>~* 为不区分大小写匹配；!~为不区分大小写不匹配</li>
</ul>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;例如下面设定nginx在用户使用ie的使用重定向到/nginx-ie目录下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">if</span> (<span class="variable">$http_user_agent</span> ~ MSIE) &#123;</div><div class="line">    rewrite ^(.*)$ /nginx-ie/<span class="variable">$1</span> <span class="built_in">break</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;文件和目录判断</p>
<ul>
<li>-f和!-f判断是否存在文件</li>
<li>-d和!-d判断是否存在目录</li>
<li>-e和!-e判断是否存在文件或目录</li>
<li>-x和!-x判断文件是否可执行</li>
</ul>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;例如下面设定nginx在文件和目录不存在的时候重定向：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">if</span> (!-e <span class="variable">$request_filename</span>) &#123;</div><div class="line">    proxy_pass http://127.0.0.1;</div><div class="line">&#125;</div><div class="line"><span class="built_in">return</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;返回http代码，例如设置nginx防盗链：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">location ~* \.(gif|jpg|png|swf|flv)$ &#123;</div><div class="line">    valid_referers none blocked www.test.com www.test1.com;</div><div class="line">    <span class="keyword">if</span> (<span class="variable">$invalid_referer</span>) &#123;</div><div class="line">        <span class="built_in">return</span> 404;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Nginx/15. nginx域名跳转/">nginx域名跳转</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/LNMP/">LNMP</a> <a class="article__tag-link" href="/tags/Nginx/">Nginx</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;配置 nginx 虚拟主机配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@lnmp ~]<span class="comment"># vim /usr/local/nginx/conf/vhosts/123.conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;配置如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">if</span> (<span class="variable">$host</span> != <span class="string">'www.123.com'</span>)</div><div class="line">&#123;</div><div class="line">    rewrite ^/(.*)$ http://www.123.com/<span class="variable">$1</span> permanent;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/nginx%E5%9F%9F%E5%90%8D%E8%B7%B3%E8%BD%AC/01.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;检测配置是否有错，并重新加载 nginx 服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@lnmp ~]<span class="comment"># service nginx configtest</span></div><div class="line">[root@lnmp ~]<span class="comment"># service nginx reload</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;curl 检测</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@lnmp ~]<span class="comment"># curl -x127.0.0.1:80 www.234.com/123 -I</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/nginx%E5%9F%9F%E5%90%8D%E8%B7%B3%E8%BD%AC/02.png?raw=true" alt=""></figure></p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Nginx/14. nginx用户认证/">nginx用户认证</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/LNMP/">LNMP</a> <a class="article__tag-link" href="/tags/Nginx/">Nginx</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;nginx 如何做用户认证，首先需要安装 apache ，也可以使用 yum install -y httpd 安装。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@lnmp ~]<span class="comment"># yum install -y httpd</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后生成密码文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@lnmp ~]<span class="comment"># htpasswd -c -m /usr/local/nginx/conf/.htpasswd yanyi</span></div><div class="line">New password: </div><div class="line">Re-type new password: </div><div class="line">Adding password <span class="keyword">for</span> user yanyi</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这样就添加了 yanyi 用户，第一次添加需要加 -c 参数，第二次添加时不需要 -c 参数。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在 nginx 虚拟主机配置文件中添加</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">location ~ .*admin\.php$ &#123;</div><div class="line">    auth_basic <span class="string">"yanyi auth"</span>;</div><div class="line">    auth_basic_user_file /usr/<span class="built_in">local</span>/nginx/conf/.htpasswd;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这样就会把请求 admin 访问给限制了，只有输入用户名和密码才可以继续访问。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这是会出现无法解析 PHP 的情况，把 php 的相关文件复制上来即可</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/nginx%E7%94%A8%E6%88%B7%E8%AE%A4%E8%AF%81/01.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;用 curl 命令验证</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@lnmp www]<span class="comment"># curl -x127.0.0.1:80 -uyanyi:123456 123.com/admin.php</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;参数 -u 后面跟用户名和密码</p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Nginx/13. LNMP安装 Discuz！/">LNMP安装 Discuz！</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/LNMP/">LNMP</a> <a class="article__tag-link" href="/tags/Nginx/">Nginx</a>
			</span>
		
	</div>

	

	
		<h2 id="1-下载-discuz！"><a href="#1-下载-discuz！" class="headerlink" title="1.下载 discuz！"></a>1.下载 discuz！</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@lnmp ~]<span class="comment"># mkdir /data/www</span></div><div class="line">[root@lnmp ~]<span class="comment"># cd /data/www</span></div><div class="line">[root@lnmp www]<span class="comment"># wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_GBK.zip</span></div><div class="line"></div><div class="line">[root@lnmp www]<span class="comment"># unzip Discuz_X3.2_SC_GBK.zip</span></div><div class="line">[root@lnmp www]<span class="comment"># mv upload/* .</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;删掉其他文件和压缩包</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@lnmp www]<span class="comment"># rm -rf readme/ utility/ upload/ Discuz_X3.2_SC_GBK.zip</span></div></pre></td></tr></table></figure>
<h2 id="2-配置第一个虚拟机"><a href="#2-配置第一个虚拟机" class="headerlink" title="2.配置第一个虚拟机"></a>2.配置第一个虚拟机</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑配置文件 /usr/local/nginx/conf/vhosts/123.conf</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">vim /usr/<span class="built_in">local</span>/nginx/conf/vhosts/123.conf</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;加入内容：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line">server</div><div class="line">&#123;</div><div class="line">    listen 80;</div><div class="line">    server_name 123.com;</div><div class="line">    index index.html index.htm index.php;</div><div class="line">    root /data/www;</div><div class="line">    location ~ .*admin\.php$ &#123;</div><div class="line">        auth_basic <span class="string">"yanyi auth"</span>;</div><div class="line">        auth_basic_user_file /usr/<span class="built_in">local</span>/nginx/conf/.htpasswd;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    location ~ \.php$ &#123;</div><div class="line">        include fastcgi_params;</div><div class="line">        <span class="comment">#fastcgi_pass unix:/tmp/php-fcgi.sock;</span></div><div class="line">        fastcgi_pass 127.0.0.1:9000;</div><div class="line">        fastcgi_index index.php;</div><div class="line">        fastcgi_param SCRIPT_FILENAME /data/www<span class="variable">$fastcgi_script_name</span>;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;保存退出后，检查配置有没错误：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@lnmp www]<span class="comment"># service nginx configtest </span></div><div class="line">nginx: the configuration file /usr/<span class="built_in">local</span>/nginx/conf/nginx.conf syntax is ok</div><div class="line">nginx: configuration file /usr/<span class="built_in">local</span>/nginx/conf/nginx.conf <span class="built_in">test</span> is successful</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;重新加载 nginx：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@lnmp www]# service nginx reload </div><div class="line">重新载入 Nginx： [确定]</div></pre></td></tr></table></figure>
<h2 id="3-配置-mysql-，给-Discuz！-增加一个账户"><a href="#3-配置-mysql-，给-Discuz！-增加一个账户" class="headerlink" title="3.配置 mysql ，给 Discuz！ 增加一个账户"></a>3.配置 mysql ，给 Discuz！ 增加一个账户</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;给 mysql root 账户设置密码，谈后命令行进入 mysql ，创建新的库，并创建一个新的帐号对该库有所有权限：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">[root@lnmp www]<span class="comment"># /usr/local/mysql/bin/mysql -uroot</span></div><div class="line"></div><div class="line">mysql&gt; create database discuz;</div><div class="line">Query OK, 1 row affected (0.02 sec)</div><div class="line"> </div><div class="line">mysql&gt; grant all on discuz.* to <span class="string">'yanyi'</span>@<span class="string">'localhost'</span> identified by <span class="string">'123456'</span>;</div><div class="line">Query OK, 0 rows affected (0.00 sec)</div><div class="line"> </div><div class="line">mysql&gt; quit</div><div class="line">Bye</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这样就创建了一个库 discuz ，然后有创建了一个用户 yanyi ，密码是 123456.</p>
<h2 id="4-安装-Discuz！"><a href="#4-安装-Discuz！" class="headerlink" title="4.安装 Discuz！"></a>4.安装 Discuz！</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;因为 123.com 这个域名是随便定义了一个，所以是不能直接访问的，需要先绑定 hosts ，其中hosts 在windows 和 linux 上都是存在的，可以把一个域名指向到一个 ip 上。windows 下的 hosts 文件路径是在：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;c:\windows\system32\drivers\etc\hosts 。用记事本打开，然后增加一行，保存：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">192.168.0.98   123.com</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这里的 192.168.0.98 是虚拟机的 ip 。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;浏览器输入：<a href="http://123.com/install/" target="_blank" rel="external">http://123.com/install/</a> ，打开页面</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/LNMP%E5%AE%89%E8%A3%85%20Discuz%EF%BC%81/01.png?raw=true" alt=""></figure></p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/LNMP%E5%AE%89%E8%A3%85%20Discuz%EF%BC%81/02.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;更改 /data/ 权限</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@lnmp www]<span class="comment"># chmod 777 -R /data/</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/LNMP%E5%AE%89%E8%A3%85%20Discuz%EF%BC%81/03.png?raw=true" alt=""></figure></p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/LNMP%E5%AE%89%E8%A3%85%20Discuz%EF%BC%81/04.png?raw=true" alt=""></figure></p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/LNMP%E5%AE%89%E8%A3%85%20Discuz%EF%BC%81/05.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这一步，数据库名，就是第三步创建的新数据库。数据库用户名和密码也是第三步创建的用户和密码。管理员密码一定要记得。点下一步后，就会看到安装数据库的过程，然后到 “discuz 应用中心”的页面，直接点右下角“点此访问”，就安装成功discuz 论坛了。</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/LNMP%E5%AE%89%E8%A3%85%20Discuz%EF%BC%81/06.png?raw=true" alt=""></figure></p>

	

	

</article>





	<span class="different-posts">📖 <a href="/page/26">more posts</a> 📖</span>



	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
